package com.szxy.miaosha.dao;

import com.szxy.miaosha.vo.GoodsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author:zwer
 * @Date:2020/9/8 21:25
 * @Description:com.szxy.miaosha.dao
 * @Version:1.0
 **/
@Mapper
public interface GoodsMapper {

    @Select("select g.id, mg.goods_name, g.goods_title, g.goods_img, g.goods_price, mg.miaosha_price,stock_count from miaosha_goods mg left join goods g on mg.id = g.id")
    List<GoodsVo> listGoods();

    @Select("select mg.start_date, mg.end_date, g.id, mg.goods_name, g.goods_title, g.goods_img, g.goods_price, mg.miaosha_price,stock_count from miaosha_goods mg left join goods g on mg.id = g.id where mg.goods_id = #{goods_id}")
    GoodsVo getGoodsByGoodsId(@Param("goods_id") Long goodsId);

    @Update("update miaosha_goods set stock_count = stock_count - 1 where goods_id = #{goods_id}")
    void updateMiaoGoodsStockByGoodsId(@Param("goods_id") long goodsId);
}
